package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.dto.LoginAuthDto;
import net.wanho.service.LoginAuthService;
import net.wanho.vo.AjaxResult;
import net.wanho.vo.LoginInfoVo;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Author: Lun
 * Date: 2025-07-22 19:26
 * Description: <描述>
 */
@RestController
@RequiredArgsConstructor
public class LoginAuthController {
    private final LoginAuthService loginAuthService;

    @GetMapping("/captchaImage")
    public AjaxResult captchaImage() {
        return AjaxResult.success(loginAuthService.captchaImage());
    }


    @PostMapping("/login")
    public AjaxResult login(@RequestBody @Valid LoginAuthDto loginAuthDto) {
        return AjaxResult.success("成功",loginAuthService.login(loginAuthDto));
    }

    @GetMapping("/curr-user")
    public AjaxResult currUser() {
        LoginInfoVo loginInfoVo = loginAuthService.currUser();
        System.out.println(loginInfoVo);
        return AjaxResult.success(loginInfoVo);
    }

    @DeleteMapping("/logout")
    public AjaxResult logout() {
        loginAuthService.logout();
        return AjaxResult.success();
    }
}
